package com.hctg.forced2sleep.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;

import com.actor.myandroidframework.dialog.ViewBindingDialog;
import com.actor.myandroidframework.utils.TextUtils2;
import com.actor.myandroidframework.utils.toaster.ToasterUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.hctg.forced2sleep.adapter.LimitEditAdapter;
import com.hctg.forced2sleep.databinding.DialogLimitEditBinding;

import java.util.List;

/**
 * description: 限制修改
 *
 * @author : ldf
 * date       : 2025/1/2 on 16
 * @version 1.0
 */
public class LimitEditDialog extends ViewBindingDialog<DialogLimitEditBinding> {

    private final LimitEditAdapter mAdapter = new LimitEditAdapter();
    private int startHour = 3, startMinute = 0, endHour = 4, endMinute = 0;

    public LimitEditDialog(@NonNull Context context) {
        super(context);
        setWidthPercent(0.888888f, SizeUtils.dp2px(308f));
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //开始时间
        viewBinding.tvStart.setOnClickListener(v -> {
            new HourMinuteSelectDialog(getContext(), null, startHour, startMinute, (hour, minute) -> {
                startHour = hour;
                startMinute = minute;
                viewBinding.tvStart.setText(TextUtils2.getStringFormat("%02d:%02d", hour, minute));
            }).show();
        });
        //结束时间
        viewBinding.tvEnd.setOnClickListener(v -> {
            new HourMinuteSelectDialog(getContext(), null, endHour, endMinute, (hour, minute) -> {
                endHour = hour;
                endMinute = minute;
                viewBinding.tvEnd.setText(TextUtils2.getStringFormat("%02d:%02d", hour, minute));
            }).show();
        });
        //应急强制修改(预防突发情况, 建议开启)
        viewBinding.btnMore.setOnClickListener(v -> {
            v.setSelected(!v.isSelected());
            viewBinding.llMore.setVisibility(v.isSelected() ? View.VISIBLE: View.GONE);
        });

        //禁用时间段缴纳罚金修改
        viewBinding.ivQuitMoney.setOnClickListener(v -> {
            v.setSelected(!v.isSelected());
            viewBinding.recyclerView.setVisibility(v.isSelected() ? View.VISIBLE: View.GONE);
        });

        viewBinding.tvCancel.setOnClickListener(v -> dismiss());
        viewBinding.tvConfirm.setOnClickListener(v -> {
            ToasterUtils.error("功能还在做");
            dismiss();
        });

        List<String> data = mAdapter.getData();
        data.add("1元");
        data.add("5元");
        data.add("10元");
        data.add("15元");
        data.add("20元");
        data.add("30元");
        data.add("40元");
        data.add("50元");
        viewBinding.recyclerView.setAdapter(mAdapter);
    }
}
